﻿using Org.BouncyCastle.Crypto.Parameters;
using System.Net;

namespace MyTRCP.Common.MyProtocol
{
    public class SessionInfo
    {
        public Guid SessionId { get; set; }
        public int LastRecvDatagramId { get; set; }
        public bool LastRecvDatagramChangeId { get; set; }
        public DateTime LastCommDateTime { get; set; }
        public ParametersWithIV? SessionKey { get; set; }
        public IPEndPoint? LastEP { get; set; }
        public int RepeatTimes { get; set; }
        public int LastSendDatagramId { get; set; }
        public int NextDatagramId
        {
            get
            {
                if (LastRecvDatagramId == int.MaxValue)
                {
                    return 0;
                }
                else
                {
                    return LastRecvDatagramId + 1;
                }
            }
        }
        public int NextResponseDatagramId
        {
            get
            {
                if (NextDatagramId == int.MaxValue)
                {
                    return 0;
                }
                else
                {
                    return NextDatagramId + 1;
                }
            }
        }
        public bool NextDatagramChangeId
        {
            get
            {
                if (NextDatagramId == 0)
                {
                    return true;
                }
                else
                {
                    return false;
                }
            }
        }
        public bool NextResponseDatagramChangeId
        {
            get
            {
                if (NextResponseDatagramId == 0)
                {
                    return true;
                }
                else
                {
                    return false;
                }
            }
        }
        public bool UseCrypto
        {
            get
            {
                return SessionKey != null;
            }
        }
        public void AddDatagramId()
        {
            LastRecvDatagramId++;
        }
    }
}

